<?php
declare(strict_types=1);

namespace SixShop\Payment\Model;

use SixShop\Payment\Enum\NumberBizEnum;
use SixShop\Payment\Enum\RefundStatusEnum;
use think\Model;
use think\model\relation\BelongsTo;

class ExtensionRefundModel extends Model
{
    protected function setOutRefundNoAttr($value, $data): string
    {
        return generate_number(NumberBizEnum::ORDER_REFUND);
    }

    protected function getOptions(): array
    {
        return [
            'name' => 'extension_refund',
            'type' => [
                'status' => RefundStatusEnum::class,
                'amount' => 'float',
                'refund_param' => 'json',
                'refund_result' => 'json',
            ],
            'insert' => ['out_refund_no'],
            'readonly' => ['payment_id', 'order_sn', 'out_refund_no', 'reason', 'amount'],
        ];
    }

    public function payment(): BelongsTo
    {
        return $this->belongsTo(ExtensionPaymentModel::class, 'payment_id', 'id');
    }
}